package pers.zc.activiti.aop.fanshe;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * @description 获取私有变量1
 * @Author Lin FuYuan
 * @date 2020/6/15
 */
@Slf4j
@Lazy(false)
@Component
public class PrivateClass implements ApplicationContextAware {


    public static void main(String[] args) throws Exception {
        Class<?> obj = TestPrivate.class;
        Field[] f = obj.getDeclaredFields();
        for(Field field : f){
            field.setAccessible(true);
            System.out.println(field.getName());
        }
    }

    @SneakyThrows
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(Service.class);
        beansWithAnnotation.forEach((k,v)->{
            System.out.println("k:"+k+" v:"+v.getClass().getName());
            Class<?> obj = v.getClass();
            Field[] f = obj.getDeclaredFields();
            for(Field field : f){
                field.setAccessible(true);
                System.out.println(field.getName());
            }

        });
    }
}
